package com.banshuibao.bsb_android.adapter;

import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.model.OfficeModel;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.TimeUtil;

/**
 * Created by zyh on 2017/12/20.
 */

public class OfficeListAdapter extends MyBaseAdapter<OfficeModel.Data> {


    public OfficeListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        OfficeViewHolder holder;
        if (view == null) {
            holder = new OfficeViewHolder();
            view = layoutInflater.inflate(R.layout.item_home_office, viewGroup, false);
            holder.title = view.findViewById(R.id.title);
            holder.tag = view.findViewById(R.id.tag);
            view.setTag(holder);
        } else
            holder = (OfficeViewHolder) view.getTag();
        final OfficeModel.Data item = getItem(i);
        if (item != null) {
            holder.title.setText(item.getTitle());
            holder.tag.setText(item.getLable());
            GradientDrawable gradientDrawable = (GradientDrawable) holder.tag.getBackground();
            if ("动态".equals(item.getLable())) {
                gradientDrawable.setColor(context.getResources().getColor(R.color.d_t_color));
            } else if ("快讯".equals(item.getLable())) {
                gradientDrawable.setColor(context.getResources().getColor(R.color.k_x_color));
            } else if ("活动".equals(item.getLable())) {
                gradientDrawable.setColor(context.getResources().getColor(R.color.h_d_color));
            } else if ("头条".equals(item.getLable())) {
                gradientDrawable.setColor(context.getResources().getColor(R.color.t_t_color));
            } else {
                gradientDrawable.setColor(context.getResources().getColor(R.color.white));
            }
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    IntentManager.goOfficeDetailActivity(context, item.getUuid());
                }
            });
        }
        return view;
    }

    private class OfficeViewHolder {
        TextView title, time, tag;
    }
}
